//ATTENTION: Long running task. If you are going to run a sync after this update run first 
//db.ReferenceUniverse.remove( { Name: { $ne: "Default" } } )

db.getSiblingDB("ClientDW_A").ReferenceUniverse.find()
  .forEach(function (doc) {
    doc.Companies.forEach(function (company) {        
        db.getSiblingDB("ClientDW_A").ReferenceUniverse.updateOne({"Companies.CapitalIQID":company.CapitalIQID}, {"$set":{"Companies.$.CapitalIqId" : new NumberInt(company.CapitalIQID.replace('IQ',""))}})
        db.getSiblingDB("ClientDW_A").ReferenceUniverse.updateOne({"Companies.CapitalIQID":company.CapitalIQID}, {"$unset":{"Companies.$.CapitalIQID" : true}})                
    })
})

db.getSiblingDB("ClientDW_B").ReferenceUniverse.find()
  .forEach(function (doc) {
    doc.Companies.forEach(function (company) {        
        db.getSiblingDB("ClientDW_B").ReferenceUniverse.updateOne({"Companies.CapitalIQID":company.CapitalIQID}, {"$set":{"Companies.$.CapitalIqId" : new NumberInt(company.CapitalIQID.replace('IQ',""))}})
        db.getSiblingDB("ClientDW_B").ReferenceUniverse.updateOne({"Companies.CapitalIQID":company.CapitalIQID}, {"$unset":{"Companies.$.CapitalIQID" : true}})                
    })
})